using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using BO;
using BL;
namespace AnimalFarm.Quarantine_manage
{
    public partial class AddQuarantine : Telerik.WinControls.UI.RadForm
    {
        B_Quarantine quarantineManager;
        B_Livestock livestockManager;
        B_HomeField homefieldManager;
        DataTable livestockData;
        public AddQuarantine()
        {
            InitializeComponent();
            quarantineManager = B_Quarantine.CreateInstance();
            livestockManager = B_Livestock.CreateInstance();
            homefieldManager = B_HomeField.CreateInstance();
            //bind data
            bindHomefieldData();
            bindLivestockData();
        }
        public void bindLivestockData()
        {
            livestockData = livestockManager.GetAllLivestock();
            grid_livestock.DataSource = livestockData;

        }
        public void bindHomefieldData()
        {
         DataTable dt=   homefieldManager.GetAllHomeField();
         grid_homefield.DataSource = dt;
        }
        private void radButton1_Click(object sender, EventArgs e)
        {
            if (grid_homefield.SelectedRows.Count == 0)
            {
                MessageBox.Show("select a homefield");
                return;
            }
            if (grid_livestock.SelectedRows.Count == 0)
            {
                MessageBox.Show("select a livestock");
                return;
            }
            if (txt_reason.Text.Length == 0) {
                MessageBox.Show("Enter reason");
                return;
            }
            Quarantine_Info quant = new Quarantine_Info();
            quant.LivestockID = int.Parse(grid_livestock.SelectedRows[0].Cells["LivestockID"].Value.ToString());
            quant.QuarantineDate = dtpTime.Value;
            quant.QuarantinePlaceID = int.Parse(grid_homefield.SelectedRows[0].Cells["ID"].Value.ToString());
            quant.QuarantineReason = txt_reason.Text;
            quant.ReleaseDate = DateTime.Now;
           
          bool ok=  quarantineManager.CreateOneQuarantine(quant);
            if(ok)
                MessageBox.Show("Add successfully");
            else
                MessageBox.Show("Add fail");
        }
    }
}
